import 'package:flutter/material.dart';
import 'package:flutter_architecture/viewmodels/base_view_model.dart';

/// 主题 ViewModel
/// @author: dingwen
/// @date: 2020/12/28

class ThemeViewModel extends BaseViewModel {
  //默认为亮主题
  ThemeData themeData = getThemeData();

  //是否是亮主题
  bool lighted = true;

  ///改变主题
  changeTheme() {
    if (lighted) {
      themeData = getThemeData(lighted: false);
    } else {
      themeData = getThemeData(lighted: true);
    }
    lighted = !lighted;

    //通知依赖此ThemeViewModel的子widget更新
    notifyListeners();
  }

  static ThemeData getThemeData({bool lighted = false}) {
    //todo 自适应
    //字体大小
    double fontSize = 16.0;
    return ThemeData(
      textTheme: TextTheme(
          subtitle1: TextStyle(
        color: lighted ? Colors.white : Colors.black,
        fontSize: fontSize,
      )),
      backgroundColor: lighted ? Colors.black : Colors.white,
      brightness: lighted ? Brightness.dark : Brightness.light,
      primaryColor: lighted ? Color(0xff000000) : Colors.deepOrange,
      appBarTheme: AppBarTheme(
        elevation: 0,
        textTheme: TextTheme(
            subtitle1: TextStyle(
          color: Colors.white,
          fontSize: fontSize,
        )),
      ),
    );
  }

  ///有服务器控制app主题可在此实现
  @override
  fetchData() {}
}
